package com.aftvc.springbootstartdemo.service.impl;

import com.aftvc.springbootstartdemo.pojo.ActCardResult;
import com.aftvc.springbootstartdemo.mapper.ActCardResultMapper;
import com.aftvc.springbootstartdemo.service.ActCardResultService;
import com.aftvc.springbootstartdemo.utils.DatabaseUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author YH
 * @since 2022-08-11
 */
@Service
public class ActCardResultServiceImpl extends ServiceImpl<ActCardResultMapper, ActCardResult> implements ActCardResultService {
    @Autowired
    private ActCardResultMapper actCardResultMapper;

    @Override
    public List<ActCardResult> getSelectInfo(String str) {
        return actCardResultMapper.getSelectInfo(str);
    }

    @Override
    public List<Map<String, Object>> getColumnNames() {
        List<Map<String, Object>> list = new ArrayList<>();
        List<String> columnNames = DatabaseUtil.getColumnNames("act_card_result");
        List<String> columnTypes = DatabaseUtil.getColumnTypes("act_card_result");
        for (int i = 0; i < columnNames.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            if(columnTypes.get(i).equals("VARCHAR") ||
                    columnTypes.get(i).equals("TEXT") ||
                    columnTypes.get(i).equals("CHAR")){
                map.put("type","text");
            }else if(columnTypes.get(i).equals("DATETIME") ){
                map.put("type","date");
            }
            else{
                map.put("type",columnTypes.get(i));
            }
            map.put("id",columnNames.get(i));
            map.put("label",columnNames.get(i));
            list.add(map);
        }
        return list;
    }
}
